//
//  FnSplashAd.m
//  flutter_fn_sdk
//
//  Created by Chenas on 2022/7/3.
//

#import "FnSplashAd.h"
#import "FnSdkHeader.h"

@interface FnSplashAd ()<FNLoadSplashAdDelegate>

@property (strong, nonatomic) FNInitializeSplash *initializeSplash;

@end

@implementation FnSplashAd



+(instancetype)loadAdWithAppId:(NSString *)appId adsId:(NSString *)adsId isRelease:(BOOL)release{

    return [[FnSplashAd alloc] initWithAppId:appId adsId:adsId isRelease:release];
}

- (instancetype)initWithAppId:(NSString *)appId adsId:(NSString *)adsId isRelease:(BOOL)release
{
    self = [super init];
    if (self) {
        self.initializeSplash = [[FNInitializeSplash alloc] initWithPlacementId:appId adsId:adsId];
        //开发环境(测试ID)为NO 生产环境(正式ID)为YES
        self.initializeSplash.isRelease = release;
        self.initializeSplash.delegate = self;
        [self.initializeSplash loadFnSplashAd];
    }
    return self;
}

/**
 *  开屏广告成功展示
 */
- (void)fnSplashShow{
    if (self.onShow) {
        self.onShow();
    }
}


/**
 *  开屏广告失败（最终请求失败）
 */
- (void)fnSplashError:(NSError *)error{
    NSLog(@"开屏广告错误：%@",error);
    if (self.onError) {
        self.onError(error);
    }
}


/**
 *  开屏广告关闭回调
 */
- (void)fnSplashClosed{
    if (self.onClosed) {
        self.onClosed();
    }
}


/**
 *  开屏广告点击回调
 */
- (void)fnSplashClicked{
    if (self.onClicked) {
        self.onClicked();
    }
}

- (void)dealloc{
    self.initializeSplash.delegate = nil;
    NSLog(@"FnSplashAd - dealloc");
}

@end
